import { baseRequestClient } from './request';

/** 用户列表查询入参 */
export interface GetUserListPayload {
    nickname?: string;
    tel?: string;
    pageNum: number;
    pageSize: number;
}

/** 用户列表项（根据后端实际返回做兼容映射） */
export interface UserListItem {
    id?: string | number;
    avatar?: string;
    nickname?: string;
    mobile?: string;
    openid?: string;
    authorizedAt?: string;
    createdAt?: string;
}

/**
 * 获取用户列表（POST）
 * 后端路径示例：/user/list
 */
export async function getUsers(payload: GetUserListPayload) {
    const res = await baseRequestClient.post('/user/page', payload);
    // 后端结构：{ code: 200, data: { records, total, size, current, pages } }
    return res?.data;
}

/** 新增用户入参 */
export interface UserAddPayload {
    nickname: string;
    tel: string;
    gender?: string;
    address?: string;
}

/** 编辑用户入参 */
export interface UserUpdatePayload {
    id: string | number;
    nickname?: string;
    tel?: string;
    gender?: string;
    address?: string;
}

/**
 * 新增用户（POST /user/add）
 */
export async function addUser(payload: UserAddPayload) {
    const res = await baseRequestClient.post('/user/add', payload);
    return res?.data;
}

/**
 * 编辑用户（POST /user/update）
 */
export async function updateUser(payload: UserUpdatePayload) {
    const res = await baseRequestClient.post('/user/update', payload);
    return res?.data;
}

/**
 * 获取访问统计（GET /visit/count）
 */
export async function getVisitCount(params?: { startTime?: string; endTime?: string }) {
    const res = await baseRequestClient.get('/visit/count', { params });
    return res?.data;
}

